<?php

namespace SinoPHP\BbdBoss\Traits;

use ErrorException;
use InvalidArgumentException;
use SinoPHP\BbdBoss\Library\AppAuth;
use SinoPHP\BbdBoss\Defines\StaticConfig;
use SinoPHP\BbdBoss\Library\JwtHelper;

/**
 * API接口参数校验(通用)
 */
trait ApiParamsValidate {

    /**
     * 校验TOKEN
     */
    public function checkToken() {
        if (empty($_SERVER['HTTP_AUTHORIZATION'])) {
            throw new InvalidArgumentException('', 101010);
        }

        $token = $_SERVER['HTTP_AUTHORIZATION'];
        if (!JwtHelper::validateToken($token)) {
            throw new ErrorException('', 101011);
        }

        return true;
    }

}
